Bases: WidgetMixin, _AbstractButtonBase
Abstract button widget base class, providing functionality common to buttons.
Source code in prettyqt/widgets/abstractbutton.py
| class AbstractButtonMixin(widgets.WidgetMixin, _AbstractButtonBase):
"""Abstract button widget base class, providing functionality common to buttons."""
def __bool__(self):
return self.isChecked()
def set_icon(self, icon: datatypes.IconType):
"""Set the icon for the button.
Args:
icon: icon to use
"""
icon = iconprovider.get_icon(icon)
self.setIcon(icon)
def get_icon(self) -> gui.Icon | None:
icon = self.icon()
return None if icon.isNull() else gui.Icon(icon)
def set_style_icon(
self,
icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap,
size: datatypes.SizeType = 15,
):
"""Set theme icon for the button.
Args:
icon: icon to use
size: icon size
"""
qicon = self.style().standardIcon(
widgets.style.STANDARD_PIXMAP.get_enum_value(icon), None, self
)
self.set_icon(qicon)
self.setIconSize(datatypes.to_size(size))
def set_shortcut(self, shortcut: datatypes.KeySequenceType):
self.setShortcut(datatypes.to_keysequence(shortcut))
def get_shortcut(self) -> gui.KeySequence:
return gui.KeySequence(
self.shortcut().toString(), gui.KeySequence.SequenceFormat.PortableText
)
def setText(self, text: str):
if not self.objectName() and widgets.application.is_debug():
self.setObjectName(text)
super().setText(text)
set_text = setText
def set_icon_size(self, size: datatypes.SizeType):
"""Set size of the icon."""
self.setIconSize(datatypes.to_size(size))
def get_icon_size(self) -> core.Size:
return core.Size(self.iconSize())
def get_value(self) -> bool:
return self.isChecked()
def set_value(self, value: bool):
self.setChecked(value)
|
Set the icon for the button.
Parameters:
| Name |
Type |
Description |
Default |
icon
|
IconType
|
|
required
|
Source code in prettyqt/widgets/abstractbutton.py
| def set_icon(self, icon: datatypes.IconType):
"""Set the icon for the button.
Args:
icon: icon to use
"""
icon = iconprovider.get_icon(icon)
self.setIcon(icon)
|
Set size of the icon.
Source code in prettyqt/widgets/abstractbutton.py
| def set_icon_size(self, size: datatypes.SizeType):
"""Set size of the icon."""
self.setIconSize(datatypes.to_size(size))
|
Set theme icon for the button.
Parameters:
| Name |
Type |
Description |
Default |
icon
|
StandardPixmapStr | StandardPixmap
|
|
required
|
size
|
SizeType
|
|
15
|
Source code in prettyqt/widgets/abstractbutton.py
| def set_style_icon(
self,
icon: widgets.style.StandardPixmapStr | widgets.QStyle.StandardPixmap,
size: datatypes.SizeType = 15,
):
"""Set theme icon for the button.
Args:
icon: icon to use
size: icon size
"""
qicon = self.style().standardIcon(
widgets.style.STANDARD_PIXMAP.get_enum_value(icon), None, self
)
self.set_icon(qicon)
self.setIconSize(datatypes.to_size(size))
|